<?php

class PEAR2_REST_Server {

	protected $router = null;

	protected $controller = null;

	protected $input = null;

	protected $authenticator = null;

	protected $output = null;

	public function __construct() {
		$this->router = new PEAR2_REST_Server_Router();
		$this->input = new PEAR2_REST_Server_Input();
		$this->authenticator = new PEAR2_REST_Server_Authenticator();
		$this->output = new PEAR2_REST_Server_Output();
	}

	public function run() {

		$route = $this->router->buildRoute($this->input);

		$user = $this->authenticator->authenticate($this->input,$this->output);
		if ($user->isLoggedIn()) {
			$route->run($this->input,$this->output,$user);
		}

		$this->output->flush();
	}
}
